package com.scorpionstudio.girlstoryshop.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.loopj.android.image.SmartImageView;
import com.scorpionstudio.girlstoryshop.DetailClothesActivity;
import com.scorpionstudio.girlstoryshop.R;
import com.scorpionstudio.girlstoryshop.bean.ItemClothes;
import com.scorpionstudio.girlstoryshop.data.CacheItems;

public class LoadingAdapter extends ArrayAdapter<ItemClothes> {
	private LayoutInflater mInflater;
	private Activity mActivity;
	public LoadingAdapter(Activity context,
			int textViewResourceId, List<ItemClothes> objects) {
		super(context, textViewResourceId, objects);
		this.mActivity = context;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder mHolder;
		final ItemClothes mItemsNew = this.getItem(position);
		if(convertView == null){
			mHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.items_news,parent, false);
			mHolder.tvDescription = (TextView) convertView.findViewById(R.id.tv_description);
			mHolder.mImage = (SmartImageView) convertView.findViewById(R.id.imv_avata_item);
			mHolder.tvCost = (TextView) convertView.findViewById(R.id.tv_loading_cost);
			convertView.setTag(mHolder);
		}else{
			mHolder = (ViewHolder) convertView.getTag();
		}
		convertView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				CacheItems.getInstance().setmItem(mItemsNew);
				Intent mIntent = new Intent(mActivity,DetailClothesActivity.class);
				mActivity.startActivityForResult(mIntent,100);
			}
		});
		mHolder.tvDescription.setText(mItemsNew.getDescriptionImg().trim());
		String urlIMG = mItemsNew.getUrlImg();
		mHolder.mImage.setImageUrl(urlIMG);
		mHolder.tvCost.setText("Giá sản phẩm :"+mItemsNew.getCostItems().trim());
		return convertView;
	}
	class ViewHolder{
		private SmartImageView  mImage;
		private TextView tvDescription,tvCost;
	}
}
